{extend name='common/_container'} {block name="content"}
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <div class="row" id="searchGroup">
                            <div class="col-sm-2">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle"
                                                type="button">姓名
                                        </button>
                                    </div>
                                    <input type="text" autocomplete="off" class="form-control" id="name_s"
                                           placeholder="姓名"/>
                                </div>
                            </div>
                            <div class="col-sm-2">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">红娘等级</button>
                                    </div>
                                    <select name="level_id" id="level_id" class="form-control">
                                        <option value="">选择红娘等级</option>
                                        {foreach $level_rows as $key=>$vo }
                                        <option value="{$vo['id']}">{$vo['name']}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>


<!--                            <div class="col-sm-2">-->
<!--                                <div class="input-group">-->
<!--                                    <div class="input-group-btn">-->
<!--                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle"-->
<!--                                                type="button">市区-->
<!--                                        </button>-->
<!--                                    </div>-->
<!--                                    <input type="text" autocomplete="off" class="form-control" id="city"-->
<!--                                           placeholder="市区"/>-->
<!--                                </div>-->
<!--                            </div>-->

                            <div class="col-sm-3">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle"
                                                type="button">创建时间范围
                                        </button>
                                    </div>
                                    <input type="text" autocomplete="off" placeholder="时间范围" class="form-control"
                                           id="createtime">
                                </div>
                            </div>


                            <!--状态-->
                            <div class="col-sm-2">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle"
                                                type="button">状态
                                        </button>
                                    </div>
                                    <select class="form-control" id="status">
                                        <option value="">请选择</option>
                                        <option value="1">通过</option>
                                        <option value="0">待审核</option>
                                        <option value="2">拒绝</option>
                                    </select>
                                </div>
                            </div>
                            <!-- search end -->
                            <div class="col-sm-1">
                                <button type="button" class="btn btn-success " onclick="CodeGoods.search()" id="">
                                    <i class="fa fa-search"></i>&nbsp;搜索
                                </button>
                            </div>
                        </div>
                        <div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
                        </div>

                        <table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
                            <thead>
                            <tr>
                                <th data-field="selectItem" data-checkbox="true"></th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var CodeGoods = {id: "CodeGoodsTable", seItem: null, table: null, layerIndex: -1};

    CodeGoods.initColumn = function () {
        return [
            {field: 'selectItem', checkbox: true},
            {title: '编号', field: 'matchmaker_id', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '年龄', field: 'age', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '手机号码', field: 'phone', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '昵称', field: 'nickname', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '头像', field: 'avatar', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.avatarFormatter},
            {title: '下级用户数', field: 'child_num', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '下级佳人数', field: 'lower_matchmaker_num', visible: true, align: 'center', valign: 'middle',sortable: true},
            {
                title: '操作',
                field: '',
                visible: true,
                align: 'center',
                valign: 'middle',
                formatter: CodeGoods.buttonFormatter
            },
        ];
    };

    CodeGoods.avatarFormatter = function (value, row, index) {
        if (value) {
            return "<a href=\"javascript:void(0)\" onclick=\"openImg('" + value + "')\"><img height='30' src=" + value + "></a>";
        }
    }

    var gdata = []
    CodeGoods.choose = function (index) {
        parent.GetTopValue(gdata[index]);
        index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    CodeGoods.buttonFormatter = function (value, row, index) {
        gdata[index] = row
        var str = '';
        str += '<button type="button" class="btn btn-success btn-xs" title="选择"  onclick="CodeGoods.choose(' + index + ')"><i class="fa fa-pencil"></i>&nbsp;选择</button>&nbsp;';
        return str;
    }

    CodeGoods.is_personalFormatter = function (value, row, index) {
        if (value !== null) {
            var value = value.toString();
            switch (value) {
                case '1':
                    return '<span class="label label-success">个人</span>';
                    break;
                case '0':
                    return '<span class="label label-warning">机构</span>';
                    break;
            }
        }
    }

    CodeGoods.createtimeFormatter = function (value, row, index) {
        if (value) {
            return formatDateTime(value, 'Y-m-d H:i:s');
        }
    }

    CodeGoods.statusFormatter = function (value, row, index) {
        if (value !== null) {
            var value = value.toString();
            switch (value) {
                case '1':
                    return '<span class="label label-success">通过</span>';
                    break;
                case '0':
                    return '<span class="label label-warning">待审核</span>';
                    break;
                case '2':
                    return '<span class="label label-info">拒绝</span>';
                    break;
            }
        }
    }

    CodeGoods.formParams = function () {
        var queryData = {};
        queryData['offset'] = 0;
        queryData['name_s'] = $("#name_s").val();
        queryData['city'] = $("#city").val();
        queryData['is_personal'] = $("#is_personal").val();
        queryData['organization_name'] = $("#organization_name").val();
        queryData['level_id'] = $("#level_id").val();
        queryData['createtime_start'] = $("#createtime").val().split(" - ")[0];
        queryData['createtime_end'] = $("#createtime").val().split(" - ")[1];
        queryData['status'] = $("#status").val();
        return queryData;
    }

    CodeGoods.check = function () {
        var selected = $('#' + this.id).bootstrapTable('getSelections');
        if (selected.length == 0) {
            Feng.info("请先选中表格中的某一记录！");
            return false;
        } else {
            CodeGoods.seItem = selected;
            return true;
        }
    };


    CodeGoods.view = function (value) {
        if (value) {
            var index = layer.open({
                type: 2,
                title: '查看详情',
                area: ['800px', '100%'],
                fix: false,
                maxmin: true,
                content: Feng.ctxPath + '/ZhMatchmaker/view?matchmaker_id=' + value
            });
            if (!IsPC()) {
                layer.full(index)
            }
        } else {
            if (this.check()) {
                var idx = '';
                $.each(CodeGoods.seItem, function () {
                    idx += ',' + this.matchmaker_id;
                });
                idx = idx.substr(1);
                if (idx.indexOf(",") !== -1) {
                    Feng.info("请选择单条数据！");
                    return false;
                }
                var index = layer.open({
                    type: 2,
                    title: '查看详情',
                    area: ['800px', '100%'],
                    fix: false,
                    maxmin: true,
                    content: Feng.ctxPath + '/ZhMatchmaker/view?matchmaker_id=' + idx
                });
                this.layerIndex = index;
                if (!IsPC()) {
                    layer.full(index)
                }
            }
        }
    }
    //lwx 下级用户数
    CodeGoods.childList = function (value) {
        if (value) {
            var index = layer.open({
                type: 2,
                title: '查看下级用户',
                area: ['800px', '100%'],
                fix: false,
                maxmin: true,
                content: Feng.ctxPath + '/ZhMatchmaker/childList?matchmaker_id=' + value
            });
            if (!IsPC()) {
                layer.full(index)
            }
        } else {
            if (this.check()) {
                var idx = '';
                $.each(CodeGoods.seItem, function () {
                    idx += ',' + this.matchmaker_id;
                });
                idx = idx.substr(1);
                if (idx.indexOf(",") !== -1) {
                    Feng.info("请选择单条数据！");
                    return false;
                }
                var index = layer.open({
                    type: 2,
                    title: '查看下级用户',
                    area: ['800px', '100%'],
                    fix: false,
                    maxmin: true,
                    content: Feng.ctxPath + '/ZhMatchmaker/childList?matchmaker_id=' + idx
                });
                this.layerIndex = index;
                if (!IsPC()) {
                    layer.full(index)
                }
            }
        }
    }

    CodeGoods.search = function () {
        CodeGoods.table.refresh({query: CodeGoods.formParams()});
    };

    $(function () {
        var defaultColunms = CodeGoods.initColumn();
        var url = location.search;
        var table = new BSTable(CodeGoods.id, Feng.ctxPath + "/ZhMatchmaker/index" + url, defaultColunms, 20);
        table.setPaginationType("server");
        table.setQueryParams(CodeGoods.formParams());
        CodeGoods.table = table.init();
    });
    laydate.render({
        elem: '#createtime', type: 'datetime', range: true,
        ready: function (date) {
            $(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
            $(".laydate-main-list-1 .layui-laydate-content li ol li:last-child").click();
            $(".layui-laydate-footer [lay-type='date'].laydate-btns-time").click();
        }
    });
</script>
{/block}